package com.baizw.cultivation.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @ClassName: Weather
 * @author: 剧终1204
 * @create: 2018年04月17日 11:40
 * @Description: 根据城市获取天气信息
 * @version: V1.0
 */
public class Weather {

    private static final Logger logger = LoggerFactory.getLogger(Weather.class);
    private static final String WEATHER_API = "https://www.sojson.com/open/api/weather/json.shtml?city=%s";
    private static final String WEATHER_API_BLOG = "http://wthrcdn.etouch.cn/weather_mini?city=%s";

    /**
     * 获取天气信息
     *
     * @param city 城市名称
     * @return 天气信息
     */
    public static String getWeather(String city) {
        try {
            String result = HttpUtil.get(String.format(WEATHER_API_BLOG, city), 5000);
            logger.info("{}天气信息：{}", city, result);
            return result;
        } catch (Exception e) {
            logger.error("获取天气信息失败！", e);
        }
        return StrUtil.EMPTY;
    }

    public static void main(String[] args) {
        getWeather("三门峡");
    }
}
